﻿<UserControl x:Class="CodeSHARPer.View.Tools.FindReplaceView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             
             xmlns:conv="clr-namespace:CodeSHARPer.Converter.MessageType"
             xmlns:FRconv="clr-namespace:CodeSHARPer.Converter"
             xmlns:behav="clr-namespace:CodeSHARPer.Behaviour"
             
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" d:DesignHeight="250" d:DesignWidth="300"
             FocusManager.IsFocusScope="True">
    <UserControl.Resources>
        <FRconv:InverseBooleanConverter x:Key="InvertBooleanConv" />
        <FRconv:SearchScopeToInt x:Key="searchScopeToInt"/>
        <BooleanToVisibilityConverter x:Key="boolToVis" />
        <FRconv:BoolToInt x:Key="boolToInt"/>
        <conv:MsgTypeToResourceConverter x:Key="MsgTypeToResource" />

        <DataTemplate x:Key="FindPageTemplate">
            <StackPanel>
                <TextBlock Margin="3">Text to Find:</TextBlock>
                <ContentPresenter Content="{Binding }" />
                <StackPanel DataContext="{Binding DataContext}">

                    <TextBlock Text="Search in:"
                               Margin="3"
                               Visibility="{Binding ShowSearchIn, Mode=OneWay, Converter={StaticResource boolToVis}}" />

                    <ComboBox SelectedIndex="{Binding SearchIn, Mode=TwoWay,Converter={StaticResource searchScopeToInt}}" Margin="0 0 0 3" 
                              Visibility="{Binding ShowSearchIn, Converter={StaticResource boolToVis}}"
                              HorizontalAlignment="Stretch">
                        <ComboBoxItem>Current Document</ComboBoxItem>
                        <ComboBoxItem>All Open Documents</ComboBoxItem>
                    </ComboBox>
                    <Expander Header="Options" IsExpanded="False">
                        <StackPanel>
                            <CheckBox Margin="1" Name="chkCaseSensitive" IsChecked="{Binding CaseSensitive, Mode=TwoWay}">Case Sensitive</CheckBox>
                            <CheckBox Margin="1" Name="chkSearchUp" IsChecked="{Binding SearchUp, Mode=TwoWay}">Search up</CheckBox>
                            <CheckBox Margin="1" Name="chkWholeWord" IsChecked="{Binding WholeWord, Mode=TwoWay}">Match whole Word</CheckBox>
                            <CheckBox Margin="1" Name="chkRegex" IsChecked="{Binding UseRegEx, Mode=TwoWay}">Regular Expression</CheckBox>
                            <CheckBox Margin="1" Name="chkWildcards" IsChecked="{Binding UseWildcards, Mode=TwoWay}">Wildcards</CheckBox>
                        </StackPanel>
                    </Expander>
                </StackPanel>
            </StackPanel>
        </DataTemplate>
    </UserControl.Resources>

    <Grid>
        <TabControl Name="tabMain" Height="Auto" BorderThickness="{Binding AllowReplace,  Converter={StaticResource boolToInt}}">
            <TabItem Header="Find" Name="tabFind" IsSelected="{Binding ShowAsFind}"
                     ContentTemplate="{StaticResource FindPageTemplate}"
                     Visibility="{Binding AllowReplace, Converter={StaticResource boolToVis}}">
                <StackPanel>
                    <TextBox Text="{Binding TextToFind, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Margin="3"
                             Name="PART_TxtFind"
                             AcceptsReturn="{Binding AcceptsReturn}"
                             behav:FocusExtension.IsFocused="{Binding IsTextToFindFocused}"/>
                    <Button Content="Find Next (F3)"
                            Command="{Binding DoFindCommand}"
                            Margin="3" IsDefault="True" HorizontalAlignment="Right" Width="85" Padding="3" />
                </StackPanel>
            </TabItem>
            <TabItem Header="Replace" Name="tabReplace"
                     IsSelected="{Binding ShowAsFind, Converter={StaticResource InvertBooleanConv}}"
                     ContentTemplate="{StaticResource FindPageTemplate}"
                     Visibility="{Binding AllowReplace, Converter={StaticResource boolToVis}}">
                <StackPanel>
                    <TextBox Text="{Binding TextToFind, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Margin="3"
                             Name="PART_TxtFind2"
                             AcceptsReturn="{Binding AcceptsReturn}"
                             behav:FocusExtension.IsFocused="{Binding IsTextToFindInReplaceFocused}" />

                    <TextBlock Margin="3">Replace with:</TextBlock>
                    <TextBox Text="{Binding ReplacementText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Margin="3" Name="PART_txtReplace" AcceptsReturn="{Binding AcceptsReturn}" />

                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
                        <Button Content="Find Next (F3)"
                                Command="{Binding DoFindCommand}"
                                IsDefault="True" Margin="3" HorizontalAlignment="Right" Width="85" Padding="3" />
                        <Button Content="Replace"
                                Command="{Binding DoReplaceCommand}"
                                Margin="3" HorizontalAlignment="Right" Width="85" Padding="3" />
                        <Button Command="{Binding DoReplaceAllCommand}"
                                Content="Replace All" Margin="3" HorizontalAlignment="Right" Width="85" Padding="3" />
                    </StackPanel>
                </StackPanel>
            </TabItem>
        </TabControl>
    </Grid>

</UserControl>
